﻿using System;
using Newtonsoft.Json;

namespace Jira
{
    internal abstract class TypeConverter<T> : JsonConverter
    {
        public sealed override bool CanConvert(Type objectType)
        {
            return objectType == typeof(T);
        }


        public sealed override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            return Read(reader);
        }

        protected abstract T Read(JsonReader reader);


        public sealed override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            Write(writer, (T)value);
        }

        protected abstract void Write(JsonWriter writer, T value);
    }
}
